package cn.powerone.scm.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.powerone.common.annotation.Log;
import cn.powerone.common.core.controller.BaseController;
import cn.powerone.common.core.domain.AjaxResult;
import cn.powerone.common.enums.BusinessType;
import cn.powerone.scm.domain.ScmProductsHistory;
import cn.powerone.scm.service.IScmProductsHistoryService;
import cn.powerone.common.utils.poi.ExcelUtil;
import cn.powerone.common.core.page.TableDataInfo;

/**
 * 产品修改历史Controller
 * 
 * @author PowerOne
 * @date 2025-07-29
 */
@RestController
@RequestMapping("/scm/scmProductsHistory")
public class ScmProductsHistoryController extends BaseController
{
    @Autowired
    private IScmProductsHistoryService scmProductsHistoryService;

    /**
     * 查询产品修改历史列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmProductsHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScmProductsHistory scmProductsHistory)
    {
        startPage();
        List<ScmProductsHistory> list = scmProductsHistoryService.selectScmProductsHistoryList(scmProductsHistory);
        return getDataTable(list);
    }

    /**
     * 导出产品修改历史列表
     */
    @PreAuthorize("@ss.hasPermi('scm:scmProductsHistory:export')")
    @Log(title = "产品修改历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScmProductsHistory scmProductsHistory)
    {
        List<ScmProductsHistory> list = scmProductsHistoryService.selectScmProductsHistoryList(scmProductsHistory);
        ExcelUtil<ScmProductsHistory> util = new ExcelUtil<ScmProductsHistory>(ScmProductsHistory.class);
        util.exportExcel(response, list, "产品修改历史数据");
    }

    /**
     * 获取产品修改历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('scm:scmProductsHistory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(scmProductsHistoryService.selectScmProductsHistoryById(id));
    }

    /**
     * 新增产品修改历史
     */
    @PreAuthorize("@ss.hasPermi('scm:scmProductsHistory:add')")
    @Log(title = "产品修改历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScmProductsHistory scmProductsHistory)
    {
        return toAjax(scmProductsHistoryService.insertScmProductsHistory(scmProductsHistory));
    }

    /**
     * 修改产品修改历史
     */
    @PreAuthorize("@ss.hasPermi('scm:scmProductsHistory:edit')")
    @Log(title = "产品修改历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScmProductsHistory scmProductsHistory)
    {
        return toAjax(scmProductsHistoryService.updateScmProductsHistory(scmProductsHistory));
    }

    /**
     * 删除产品修改历史
     */
    @PreAuthorize("@ss.hasPermi('scm:scmProductsHistory:remove')")
    @Log(title = "产品修改历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scmProductsHistoryService.deleteScmProductsHistoryByIds(ids));
    }

    /**
     * 查询产品修改历史
     */
    @PreAuthorize("@ss.hasPermi('scm:scmProductsHistory:remove')")
    @Log(title = "产品修改历史", businessType = BusinessType.DELETE)
    @GetMapping("/listByProductIds/{productIds}")
    public TableDataInfo listByProductIds(@PathVariable Long[] productIds)
    {
        List<ScmProductsHistory> list = scmProductsHistoryService.selectScmProductsHistoryByProductIds(productIds);
        return getDataTable(list);
    }
}
